package com.kabuda.zhugehot200_review;

/**
 * @author kabuda
 * @date 2025-03-27 21:51
 * @description
 */
public class t80_删除有序数组中的重复项II {
    public static void main(String[] args) {
        System.out.println(removeDuplicates(new int[]{0, 0, 1, 1, 1, 1, 2, 3, 3}));
    }

    /**
     *  22234 -> 22334 ->2234 4
     * @param nums
     * @return
     */
    public static int removeDuplicates(int[] nums) {
        int slow = 2;
        for (int fast = 2; fast < nums.length; fast++) {
            //比较前两个的元素是否不相等,不想等则赋值慢指针元素
            if (nums[slow - 2] != nums[fast]) {
                nums[slow++] = nums[fast];
            }
        }
        //如果数组长度小于等于slow说明数组长度小于2,即直接返回长度即可
        return Math.min(nums.length, slow);
    }
}
